<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>本地储存</title>
</head>

<body>
    <h2>localStorage</h2>
    <button onclick="savePerson()">向localStorage中存入一个人</button><br>
    <button onclick="readPerson()">向localStorage中读取一个人</button><br>
    <button onclick="removePerson()">向localStorage中读删除一个人</button><br>
    <button onclick="deletaAll()">清空所有localStorage</button>
    <script type="text/javascript">
        let person = {
                name: 'Tom',
                age: 22,
                gender: '男'
        }

       //存
        function savePerson(){
            localStorage.setItem('person',JSON.stringify(person))
        }

        // 读
        function readPerson() {
            const result = localStorage.getItem('person')
            console.log(JSON.parse(result))
        }

        function removePerson() {
            localStorage.removeItem('person')
        }
        function deletaAll() {
            localStorage.clear()
        }
    </script>
</body>

</html>